import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

// import whoami from '@feidao/web/atom/browser/msg/whoami';

import s_get from '@dfeidao/atom-web/storage/get';


import set from '@dfeidao/atom-web/local/set';
import javadsd from '@dfeidao/atom-web/msg/javadsd';

import P03 from './P03';
import P04 from './P04';
import P05 from './P05';
import P07 from './P07';
interface Users {
	page_no: number;
	page_size: number;
	dataArray: object[];
	count: number;
}
interface B {
	docDataStore: {
		master: {
			dataArray: [{
				group_number: string
				group_name: string;
			}]
		};
	};
}

export default async function a013(fd: IFeidaoAiBrowserComponent, args: { comp_id: string, event_no: string, client_type: string }) {
	// 调用事件
	// debugger;
	fd.data.node.classList.remove('display-n');
	fd.data.node.querySelector<HTMLInputElement>('#page_name').value = '';
	// const user = await whoami(get_user_info);

	const productid = await s_get('productid');

	const comp_id = args.comp_id;
	const event_no = args.event_no;
	set(fd, 'comp_id', comp_id);
	set(fd, 'event_no', event_no);
	const client_type = args.client_type;
	set(fd, 'client_type', client_type);

	const condition = {
		param: {
			productid,
			client_type
		}
	};


	const ret = await javadsd('12', '12', 'smart_securitydsd0000012', condition) as B;
	const data = ret.docDataStore.master.dataArray;
	render(fd, data, P07, 'P07', 'inner');

	const group_number = fd.data.node.querySelector<HTMLSelectElement>('[data-name="group_number"]').value;// client_point_id 客户端

	const query = {
		productid,
		group_number,
		client_type,
		page_no: 1,
		page_size: 10
	};
	// debugger;
	const res = await nodejs<Users>('menu/zj-000004/s001', query);
	// console.log(res, '000');
	// debugger;
	// 无数据渲染P04
	if (res.count === 0) {
		render(fd, '', P03, 'P03', 'inner');
		render(fd, '', P04, 'P04', 'inner');
		fd.data.node.querySelector('[data-feidao-presentation="P05"]').innerHTML = '';
	} else if (res.count < 10) {
		render(fd, res.dataArray, P03, 'P03', 'inner');
		res.page_no = 1;
		fd.data.node.querySelector('[data-feidao-presentation="P05"]').innerHTML = '';
		fd.data.node.querySelector('[data-feidao-presentation="P04"]').innerHTML = '';
	} else {
		render(fd, res.dataArray, P03, 'P03', 'inner');
		res.page_no = 1;
		render(fd, res, P05, 'P05', 'inner');
		fd.data.node.querySelector('[data-feidao-presentation="P04"]').innerHTML = '';
	}
}
